/*
 * @Author: 张瑞
 * @Date: 2021-08-31 16:38:50
 * @LastEditors: huangl
 * @LastEditTime: 2022-01-10 15:51:10
 * @Description: file content
 * @FilePath: \vue2xComponents\customConfiguration\index.js
 */
const isProduction = ['production', 'prod'].includes(process.env.NODE_ENV);
// 本地开发代理地址
const dev = 'http://localhost:8080'
// 地图选择器
const dev1 = 'https://geo.datav.aliyun.com'

// 引入依赖
const glob = require('glob');

// cdn
// 'https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.0/theme-chalk/index.css',
const css = [ 'https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css', 'https://lib.baomitu.com/driver.js/0.9.8/driver.min.css'];
const js = [
    "https://cdn.bootcdn.net/ajax/libs/vue-router/3.1.3/vue-router.min.js",
    "https://cdn.bootcdn.net/ajax/libs/vuex/3.1.0/vuex.min.js",
    "https://cdn.bootcdn.net/ajax/libs/axios/0.18.1/axios.min.js",
    // "https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.0/index.js",
    "https://cdn.bootcdn.net/ajax/libs/js-cookie/2.2.0/js.cookie.min.js",
    "https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js",
    "https://lib.baomitu.com/lodash.js/4.17.15/lodash.min.js",
    "https://lib.baomitu.com/dayjs/1.10.5/dayjs.min.js",
    "https://gw.alipayobjects.com/os/lib/antv/g6/3.7.1/dist/g6.min.js",
    "https://lib.baomitu.com/driver.js/0.9.8/driver.min.js",
    "https://lib.baomitu.com/echarts/4.9.0-rc.1/echarts.js",
    // "https://unpkg.com/vue-i18n/dist/vue-i18n.js"
]
const proCdn = {
    css,
    js: ['https://lib.baomitu.com/vue/2.6.10/vue.min.js', ...js]
}
const devCdn = {
    css,
    js: ["https://lib.baomitu.com/vue/2.6.10/vue.js", ...js]
}
const cdn = isProduction ? proCdn : devCdn;
// 自动化加入多页面基础配置
const moduleEnvs = glob.sync(`./build/*`);
const envs = {};
let pages = {};
moduleEnvs.forEach(moduleEnv => {
    const module = moduleEnv.split('/')[2].split('.')[0];
    const env = require('../build/' + module + '.env');
    envs[module] = env;
    if (env.VUE_IS_INDEX) {
        pages['index'] = {
            entry: 'src/modules/' + module + '/main.js',
            cdn,
            title: env.VUE_APP_TITLE,
            icon: env.VUE_APP_ICO,
            rdpModule: module,
            UPDATE_TIME: new Date(),
        };
    } else {
        pages[module] = {
            entry: 'src/modules/' + module + '/main.js',
            cdn,
            title: env.VUE_APP_TITLE,
            icon: env.VUE_APP_ICO,
            filename: module + '/index.html',
            rdpModule: module,
            UPDATE_TIME: new Date(),
        };
    }
});
// 代码压缩 去除无用的打印和debugger
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

// 打包文件可视化插件,用于直观的看到文件的大小进行优化
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

// 全局转换px 至 rem
// 引入等比适配插件
const px2rem = require('postcss-px2rem')

// 配置基本大小
const postcss = px2rem({
    // 基准大小 baseSize，需要和rem.js中相同
    remUnit: 16
})
module.exports = {
    dev,
    dev1,
    envs,
    pages,
    UglifyJsPlugin,
    BundleAnalyzerPlugin,
    isProduction,
    postcss
}